/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.utils;
import java.util.*;

public class VectorFieldBinding {
    private Vector store=new Vector();
    
    public FieldBinding get(int pos){
        return (FieldBinding)store.get(pos);
    }
    
    public boolean contains(FieldBinding binding){
        return store.contains(binding);
    }
    
    public void add(FieldBinding item){
        store.add(item);
    }
    
    public boolean remove(FieldBinding item){
        return store.remove(item);
    }
    
    public FieldBinding remove(int pos){
        return (FieldBinding) store.remove(pos);
    }
    
    public int size(){
        return store.size();
    }
    
    public void setVisible(boolean visible) {
        for (int i = 0;i < size();i++) {
            get(i).setVisible(visible);
        }
    }
    
    public VectorFieldBinding get(VectorBindFieldInterface vectorField) {
        VectorFieldBinding binding = new VectorFieldBinding();
        for (int i = 0;i < size();i++) {
            for (int e = 0;e < vectorField.size();e++) {
                if (
                        get(i).getBindField().getBindable().getSourceName().equals(vectorField.get(e).getBindable().getSourceName()) &&
                        get(i).getBindField().getName().equals(vectorField.get(e).getName())
                        ) {
                    binding.add(get(i));
                }
            }
        }
        return binding;
    }
    
    public boolean haveAnyChanged(){
        for (int t=0;t<size();t++){
            if (get(t).isChanged()){
                return true;
            }
        }
        return false;
    }
    
    public void intoControl(){
        for (int t=0;t<size();t++){
            get(t).intoControl();
        }
    }
    
    public void intoBindable()
    throws BindException {
        for (int t=0;t<size();t++){
            get(t).intoBindable();
        }
    }
    
    public void resetControl() {
        for(int i = 0;i < size();i++) {
            get(i).resetControl();
        }
    }
    
    public boolean isChanged() {
        for(int i = 0;i < size();i++) {
            if (get(i).isChanged()) return true;
        }
        return false;
    }
    
    
}

